package com.mobimagic.lockscreen.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mobimagic.lockscreen.AppEnv;
import com.mobimagic.lockscreen.MobileChargingHelper;
import com.mobimagic.lockscreen.R;

public class BoostResultCardView extends LinearLayout {

    private TextView saveTime, killApps;
    private ImageView appIcon, appIcon1, appIcon2, appIcon3, appIcon4, appIcon5, appIcon6, appIcon7, appIcon8,
            appIcon9;
    private List<ImageView> appIconList;
    private static final String TAG = "BoostResultCardView";
    private List<String> mDataList;
    private String time;

    public BoostResultCardView(Context context, List<String> dataList) {
        super(context);
        mDataList = dataList;
        View.inflate(context, R.layout.boost_result_card_view, this);
        initView();
    }

    private void initView() {
        time = MobileChargingHelper.getInstance().getBoostedStr();
        saveTime = (TextView) findViewById(R.id.save_time);
        killApps = (TextView) findViewById(R.id.kill_apps);
        appIcon = (ImageView) findViewById(R.id.app_icon);
        appIcon1 = (ImageView) findViewById(R.id.app_icon1);
        appIcon2 = (ImageView) findViewById(R.id.app_icon2);
        appIcon3 = (ImageView) findViewById(R.id.app_icon3);
        appIcon4 = (ImageView) findViewById(R.id.app_icon4);
        appIcon5 = (ImageView) findViewById(R.id.app_icon5);
        appIcon6 = (ImageView) findViewById(R.id.app_icon6);
        appIcon7 = (ImageView) findViewById(R.id.app_icon7);
        appIcon8 = (ImageView) findViewById(R.id.app_icon8);
        appIcon9 = (ImageView) findViewById(R.id.app_icon9);
        appIconList = new ArrayList<ImageView>();
        appIconList.add(appIcon);
        appIconList.add(appIcon1);
        appIconList.add(appIcon2);
        appIconList.add(appIcon3);
        appIconList.add(appIcon4);
        appIconList.add(appIcon5);
        appIconList.add(appIcon6);
        appIconList.add(appIcon7);
        appIconList.add(appIcon8);
        appIconList.add(appIcon9);
        flushView();
    }

    private void flushView() {
        saveTime.setText(String.format(getResources().getString(R.string.charge_save_time), time));
        if (mDataList.size() == 0 || mDataList.isEmpty()) {
            return;
        }
        killApps.setText(String.format(getResources().getString(R.string.charging_kill_apps), mDataList.size()));
        killApps.setVisibility(View.VISIBLE);
        if (AppEnv.bAppdebug) {
            Log.i(TAG, "list.size==" + mDataList.size() + "list==" + mDataList.toString());
        }
        for (String pkg : mDataList) {
            int index = mDataList.indexOf(pkg);
            ImageView appIcon = appIconList.get(index);
            //            appIcon.setImagePackageName(pkg, R.drawable.app_box_icon_launcher);
            appIcon.setVisibility(View.VISIBLE);
        }
    }

}
